<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head> 
   <meta charset="UTF-8">
   <%@ include file="/WEB-INF/views/include/head.jsp"%>
   <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
   <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
   <c:set value="<%=ResourcesUtil.getConfig(\"outbound_status_all\")%>" var="inventoryStatusAll" />
   <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
   <script src="${ctxStatic}/js/layer.js"></script>
   <script src="${ctxStatic}/js/style.js"></script>
   <script>
 	
   /*  function clothesDetailList() {
    	var outRequestDetailId = $("#outRequestDetailId").val();
    	params={"outRequestDetailId":outRequestDetailId};
    	$.post("${ctx}/slopwork/outbound/inventoryClothesDetail",params,function(result){            
            // 回调函数赋值
            var h = $(callBackHtml(result)).find("#tableInventoryRequestDetails").html();
            $('#tableInventoryRequestDetails').html(h);
            
        },'html');
	} */
	//获取 iframe 数量 
		var frLength = window.parent.frames.length;
		//父画面下标 
		var parentIndex = frLength-2;
    /* 保存创建/编辑信息 */
    function saveForm(){
 		/* 验证  */
    	var length = $("input.inputQuantity").length;
 		var result = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var realOutQuantity = $(".inputQuantity")[i].value;
 			var clothsQuantity = $(".mQuantity")[i].value;
 			if (realOutQuantity==null||realOutQuantity=="") {
 				realOutQuantity = "0";
			}
 			if (clothsQuantity==null||clothsQuantity=="") {
 				clothsQuantity = "0";
			}
 			realOutQuantity = realOutQuantity.replace(/,/g,"");
 			clothsQuantity = clothsQuantity.replace(/,/g,"");
 			if (parseFloat(clothsQuantity)<parseFloat(realOutQuantity)) {
 				tipParent("<spring:message code="outbound_requestex_check_quantity_msg"/>");
 				return;
			}
		}
    	formUnFormat($("#inputForm"));
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/slopwork/outbound/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		saveQuantity();
    	},'json');    	
    }
    
    function saveQuantity() {
 		var outRequestDetailId = "${slopworkOutbound.outRequestDetailId}"; 		
 		var styleId = "${slopworkOutbound.styleId}";
 		var length = $("input.inputQuantity").length;
 		var result = parseFloat(0);
 		var outResult = parseFloat(0);
 		for (var i = 0; i < length; i++) {
 			var clothsQuantity = $(".materialQuantity")[i].innerHTML;
 			if (clothsQuantity==null||clothsQuantity=="") {
 				clothsQuantity = "0";
			}
 			clothsQuantity = clothsQuantity.replace(/,/g,"");
 			result += parseFloat(clothsQuantity);
		}
 		for (var i = 0; i < length; i++) {
 			var inputQuantity = $(".inputQuantity")[i].value;
 			if (inputQuantity==null||inputQuantity=="") {
 				inputQuantity = "0";
			}
 			inputQuantity = inputQuantity.replace(/,/g,"");
 			outResult += parseFloat(inputQuantity);
		}
 		var params = {"outRequestDetailId":outRequestDetailId,"styleId":styleId,"clothsQuantity":result,"realOutQuantity":outResult}
 	    	$.post("${ctx}/slopwork/outbound/saveQuantity",params,function(result){
 	    		window.parent.frames[parentIndex].requestOutDetailsList();
 	    		closeWin();
 	    	},'json');
 	    	
	}
    
    function checkQuantity(t){
    	var inputQuantity = parseInt(($(t).val()).replace(/,/g,""));
    	var thisTR = t.parentNode.parentNode;
    	var clothsQuantity = parseInt(($(thisTR).find(".mQuantity").val()).replace(/,/g,""));
    	if(clothsQuantity<inputQuantity){
    		//tipParent("<spring:message code="outbound_requestex_check_quantity_msg"/>");
    		$(t).css("color","red");
    		return false;
    	}else{
    		$(t).css("color","");
    	}
    }
 	
 	function quantityFun(t){
 		var inputQuantity = parseInt(($(t).val()).replace(/,/g,""));
    	var thisTR = t.parentNode.parentNode;
    	var clothsQuantity = parseInt(($(thisTR).find(".mQuantity").val()).replace(/,/g,""));
    	var subQuantity = clothsQuantity - inputQuantity;
    	$(thisTR).find(".clothsQuantity").html(subQuantity);
 	}
    
 	function closeThisWin() {
 		window.parent.frames[parentIndex].requestOutDetailsList();
		closeWin();
	}
   </script>
</head>
<body>
<div class="layerHeader clearfix">
	<p class="headerTitle">成衣库存</p>
    <div class="headerButton clearfix">
    <c:if test="${slopworkOutbound.outboundStatus!=inventoryStatusAll}">
    	
        <!--保存 -->
        	<button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
        
    </c:if>
        <!-- 取消 -->
        	<button type="button" onclick="closeThisWin();"><spring:message code="outbound_detail_set_close" /></button>
    </div>
</div>
<form id="inputForm" method="post">
<input type="hidden" name="id" value="${slopworkOutbound.id}"/>
<input type="hidden" id="outRequestDetailId" name="outRequestDetailId" value="${slopworkOutbound.outRequestDetailId}"/>
<input type="hidden" name="outboundCategory" value="${slopworkOutbound.outboundCategory}"/>
<input type="hidden" name="styleId" value="${slopworkOutbound.styleId}"/>
<div style="height: 20px;padding: 17px 10px;">
     <p class="tit">库存明细</p>
</div>
<div class="tableArea">
    <div class="tableScrollSm" style="overflow:auto;width:922px;height:420px;">
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                <!-- 序号 -->
                <th><p class="tab-ddcz">No.</p></th>
                <!-- 款号 -->
                <th><p class="width-125px">款号</p></th>
                <!-- 款式名称 -->
                <th><p style="width:155px;">款式名称</p></th>
                <!-- 颜色 -->
                <th><p class="width-80px">颜色</p></th>
                <!-- 尺码 -->
                <th><p class="width-80px">尺码</p></th>
                <!-- 仓库名称 -->
                <th><p class="width-80px">仓库名称</p></th>
                <!-- 货架位置 -->
                <th><p style="width:80px;">货架位置</p></th>               
                <!-- 库存数量 -->
                <th><p class="width-80px">库存数量</p></th>
                <!-- 出库数量 -->
                <th><p class="width-80px">出库数量</p></th>
                <!-- 备注 -->
                <th><p class="width-100px">备注</p></th>                                
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="tableInventoryRequestDetails">
        <c:if test="${not empty slopworkOutbound.clothsOutDetailsList}">
            <tbody>
            <c:forEach items="${slopworkOutbound.clothsOutDetailsList}" var="OutrequestDetailsInfo" varStatus="status">
            <tr>
                <!-- 序号 -->
                <td><p class="tab-ddcz">${status.index+1}</p></td>
                <!-- 款号 -->
                <td><p class="width-125px text_overflow">${OutrequestDetailsInfo.ocustomerStyleNo}</p></td>
                <!-- 款式名称 -->
                <td><p style="width:155px;" class="text_overflow">${OutrequestDetailsInfo.ostyleNameCn}</p></td>
                <!-- 颜色 -->
                <td><p class="width-80px">${OutrequestDetailsInfo.styleColor}</p></td>
                <!-- 尺码 -->
                <td><p class="width-80px">${fns:getDictName(OutrequestDetailsInfo.styleSize)}</p></td>
                <!-- 仓库名称 -->
                <td><p class="width-80px text_overflow">${OutrequestDetailsInfo.warehouseName}</p></td>
                <!-- 货架位置 -->
                <td><p class="width-80px text_overflow">${OutrequestDetailsInfo.rackPlace}</p></td>
                <!-- 库存数量 -->
                <td><p class="width-80px materialQuantity"><fmt:formatNumber value="${OutrequestDetailsInfo.clothsQuantity-OutrequestDetailsInfo.realQuantity}" pattern="#,##0.###"/></p></td>
                <!-- 出库数量 -->
                <td><input type="text" class="inputQuantity" name="clothsOutDetailsList[${status.index }].realOutQuantity" style="width:80px" value="<fmt:formatNumber value="${OutrequestDetailsInfo.realOutQuantity}" pattern="#,##0.###"/>" onblur="formatNumber(this);checkQuantity(this);" onfocus="unFormat(this)" onchange="quantityFun(this);"/></td>                
                <!-- 备注 -->
                <td><input type="text" name="clothsOutDetailsList[${status.index }].remarks" style="width:100px" value="${OutrequestDetailsInfo.remarks}"/></td>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].warehouseID" value="${OutrequestDetailsInfo.warehouseID}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].rackID" value="${OutrequestDetailsInfo.rackID}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].styleSize" value="${OutrequestDetailsInfo.styleSize}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].styleColor" value="${OutrequestDetailsInfo.styleColor}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].rackID" value="${OutrequestDetailsInfo.styleId}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].styleSizeGroup" value="${OutrequestDetailsInfo.styleSizeGroup}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].id" value="${slopworkOutbound.id}"/>
                <input type="hidden" name="clothsOutDetailsList[${status.index }].styleId" value="${OutrequestDetailsInfo.styleId}"/>
                <input type="hidden" class="mQuantity" value="<fmt:formatNumber value="${OutrequestDetailsInfo.clothsQuantity-OutrequestDetailsInfo.realQuantity+OutrequestDetailsInfo.realOutQuantity}" pattern="#,##0.###"/>"/>
            </tr>
            </c:forEach>
            </tbody>
        </c:if>    
        </table>
    </div>
</div>
<div id = "paging" ></div>
</form>
<script type="text/javascript">

</script> 
</body>
</html>